package com.txunda.zhuohired.aty.login;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ants.theantsgo.gson.GsonUtil;
import com.ants.theantsgo.util.JSONUtils;
import com.ants.theantsgo.util.L;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.smarttop.library.db.manager.AddressDictManager;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.aty.MainAty;
import com.txunda.zhuohired.aty.manage.home.ManageAty;
import com.txunda.zhuohired.base.Base2Aty;
import com.txunda.zhuohired.bean.AddressBean;
import com.txunda.zhuohired.http.pst.AccountPst;
import com.txunda.zhuohired.http.pst.MemberPst;

import java.util.Map;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/10 10:06
 * 功能描述：选择身份进入
 * 联系方式：jiahuanchen@126.com
 */

public class SelectIdentityAty extends Base2Aty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_blue_center)
    private TextView tv_layout_blue_center;

    private String data = "";
    private Bundle bundle;

    private AccountPst accountPst;

    private String member_for = "";// 用户状态：1.未注册完成（进入完善简历界面）2.已注册完成（进入用户首页）
    private String company_for = "";//Boos状态：0注册未完成（进入企业认证）1审核通过（进入企业首页）,2未审核（待审核界面）3审核失败（审核失败界面）
    private MemberPst memberPst;
    private AddressDictManager addressDictManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_blue_head);
        tv_layout_blue_center.setText("选择身份进入");
    }

    @Override
    @OnClick({R.id.tv_select_identity_job, R.id.tv_select_identity_personal})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_select_identity_job://我要求职
                //                startActivity(PerfectResumeAty.class, null);
                bundle = new Bundle();
                startActivity(MainAty.class, null);
                break;
            case R.id.tv_select_identity_personal://我要招人
                if ("0".equals(company_for)) {
                    startActivity(CompanyApproveAty.class, null);
                } else if ("1".equals(company_for)) {
                    startActivity(ManageAty.class, null);
                } else if ("2".equals(company_for)) {
                    startActivity(CompanyApproveSureAty.class, null);
                } else if ("3".equals(company_for)) {
                    startActivity(CompanyApproveFalseAty.class, null);
                }

                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_select_identity;
    }

    @Override
    protected void initialized() {
        data = application.getUserInfo().get("data");
        accountPst = new AccountPst(this);
        memberPst = new MemberPst(this);
        addressDictManager = new AddressDictManager(this);
    }

    @Override
    protected void requestData() {
        L.e("===========data==========", data);
        accountPst.choose(data);
        memberPst.region();//地址
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("choose")) {
            //            L.e("==========jsonStr==========", jsonStr);
            Map<String, String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
            member_for = data.get("member_for");
            company_for = data.get("company_for");
            return;
        }
        if (requestUrl.contains("region")) {
            //            L.e("======region====",jsonStr);
            AddressBean addressBean = GsonUtil.GsonToBean(jsonStr, AddressBean.class);
            addressDictManager.deleteaddress();
            addressDictManager.insertAddress(addressBean.getData());
            return;
        }
    }
}
